/*


import java.util.*;

import java.util.*;
//
    public void merge(int A[], int m, int B[], int n) {
        int k = A.length - 1;
        int i = m - 1;
        int j = n - 1;

        while (i >= 0 && j >= 0 && k >= 0) {
            if (A[i] >= B[j]) {
                A[k] = A[i];
                i--;
                k--;
            } else {
                A[k] = B[j];
                k--;
                j--;
            }
        }
        while (i >= 0 && k >= 0) {
            A[k] = A[i];
            k--;
            i--;
        }
        while (j >= 0 && k >= 0) {
            A[k] = B[j];
            j--;
            k--;
        }
    }
}*/
class Solution {
    public void rotate(int[] nums, int k) {
        int i = nums.length - 1;
        while(k > 0) {
            for(i = nums.length - 1; i > 0 ; i--) {
                int tmp = nums[i];
                for(i = nums.length - 2; i >= 0 ; i--) {
                    nums[i +1] = nums[i];
                }
                nums[0] =tmp;
            }
            k--;
        }
    }
}

class Solution {

    public void rotate(int[] nums, int k) {
        int left = 0;
        int right = nums.length - 1;
        reverse(nums,left,right-k);
        reverse(nums,right-k+1,right);
        reverse(nums,left,right);
    }
    public static void reverse(int[] nums,int left,int right) {
        while(left < right) {
            int tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
            left++;
            right--;
        }
    }
}